package com.no1.musicmgr.service;

import com.no1.musicmgr.entity.Music;
import com.no1.musicmgr.mapper.MusicMapper;
import com.no1.musicmgr.util.DateUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Log4j
@Service
public class MusicService {
    @Autowired
    private MusicMapper musicMapper;


    // 插入音乐
    public boolean insertMusic(Music music) {
        return musicMapper.insertMusic(music);
    }

    // 根据音乐ID删除音乐
    public boolean deleteMusicById(Integer musicId) {
        return musicMapper.deleteMusicById(musicId);
    }

    // 更新音乐信息
    public boolean updateMusic(Music music) {
        return musicMapper.updateMusic(music);
    }

    // 根据音乐ID查询音乐
    public Music selectMusicById(Integer musicId){
        return musicMapper.selectMusicById(musicId);
    }

    // 按条件查询音乐
    public ArrayList<Music> listMusic(Music music) {
        return musicMapper.listMusic(music);
    }

    // 按条件查询音乐
    public ArrayList<Music> list1Music(Music music) {
        return musicMapper.list1Music(music);
    }

    @Schema(description = "日期格式转换")
    public String formatDate(String input) {
        System.out.println("输入的日期：" + input);
        String res = null;
        if (input != null && !input.isEmpty()) {
            if (input.length() == 4) {
                if (Integer.parseInt(input) < 1232) {
                    res = DateUtil.formatDate(input);
                }
            } else {
                res = DateUtil.formatDate(input);
            }
        }
        System.out.println("转换后的日期：" + res);
        return res;
    }


    @Schema(description = "音乐列表")
    public ArrayList<Music> myMusic(String user_id) {
        return musicMapper.myMusic(user_id);
    }

    @Schema(description = "我的音乐")
    public ArrayList<Music> wodeMusic(String user_id) {
        return musicMapper.mdMusic(user_id);
    }

    @Schema(description = "取消收藏")
    public boolean deletesc(Music music) {
        return musicMapper.deletesc(music);
    }

    @Schema(description = "歌单内容")
    public ArrayList<Music> gedan(String form_Name) {
        return musicMapper.gedan(form_Name);
    }
}
